package cc.linker.steplink.crm.merchant.service;

import cc.linker.steplink.crm.merchant.dao.MallBoomBackMapper;
import cc.linker.steplink.crm.merchant.dao.ShopSetMapper;
import cc.linker.steplink.crm.response.GlobalException;
import cc.linker.steplink.crm.response.ResponseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class ShopSetService {

    @Autowired
    private ShopSetMapper shopSetMapper;

    @Autowired
    private MallBoomBackMapper mallBoomBackMapper;

    public Map<String, Object> getShopInfo(String adminId)
    {
        return  shopSetMapper.getShopInfo(adminId);
    }

    public Integer setShopInfo(Map<String,Object> params)
    {
        return  shopSetMapper.setShopInfo(params);
    }

    public void addVerify(Map<String,Object> params) throws Exception
    {
        //根据 CAS_USER_ID 获取 CUSTOMER_ID
        Map<String, Object> shopInfo= shopSetMapper.getShopInfo(params.get("adminId").toString());
        if(shopInfo == null){
            throw new GlobalException(new ResponseException(400, "账户类型错误，请退出切换账户"));
        }
        String customerId = shopInfo.get("customerId").toString();
        params.put("customerId",customerId);
        //提交认证
        Integer i = shopSetMapper.addVerify(params);
        if(i<1){
            throw new GlobalException(new ResponseException(400, "提交失败"));
        }
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("authenticateState",2);
        map.put("customerId",customerId);
        Integer n = mallBoomBackMapper.changeAuthenticateStatus(map);
        if(n<1){
            throw new GlobalException(new ResponseException(400, "提交失败"));
        }
    }

    public Map<String,Object> getWallet(String adminId) throws Exception
    {
        //根据 CAS_USER_ID 获取 CUSTOMER_ID
        Map<String, Object> shopInfo= shopSetMapper.getShopInfo(adminId);
        if(shopInfo == null){
            throw new GlobalException(new ResponseException(400, "账户类型错误，请退出切换账户"));
        }
        String customerId = shopInfo.get("customerId").toString();
        return mallBoomBackMapper.getWallet(customerId);
    }
}
